<template>
  <div class="school">
    <h2>学校名称: {{ name }}</h2>
    <h2>学校地址: {{ address }}</h2>
  </div>
</template>

<script>
  import pubsub from 'pubsub-js'

  export default {
    name: 'School',
    props: ['getSchoolName'],
    data() {
      return {
        name: '尚硅谷',
        address: '广东深圳'
      }
    },
    mounted() {
      // TODO 订阅消息
      this.pubId = pubsub.subscribe('hello', (msgName, data) => {
        console.log('有人发布了 hello 消息，hello 消息的回调执行了,方法名是：', msgName, data)
      })
    },
    beforeDestroy() {
      // TODO 取消订阅，需要通过 消息ID 来取消订阅
      pubsub.unsubscribe(this.pubId)
    }
  }
</script>

<style scoped>
  .school {
    background-color: skyblue;
    padding: 5px;
  }
</style>